<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript">
/* $(document).ready(function(){  
	var request = new Object();
	var head = new Object();
	var con = new Object();
	request.head = head;
	request.con = con;
	head.aid = "aaa";
	head.chcode = "bbb";
	head.cmd = "ccc";
	con.uuid = "111111111111111111";
	var json = JSON.stringify(request);
    $.ajax({  
        type: 'POST',  
        contentType: 'application/json',
        url: 'user/demo',  
        data: json,
        dataType: 'json',  
        success: function(data){  
            alert("新增成功！");  
        },  
        error: function(){  
            alert("error")  
        }  
    });  
}); */
</script>
<script type="text/javascript">
	function abc(){
	alert('<%=request.getContextPath()%>/file/upload');
	  var data = { fileType:$("#fileType01").val(), userId:$("#userId").val() } ;
	    $.ajaxFileUpload({
	        url: '<%=request.getContextPath()%>/file/upload',
	        secureuri: true,
	        data: data,
	        fileElementId: 'fileToUpload',
	        dataType: "json",
	        success: function (data) {
	        	if(data.status==0){
	        		$("#h2tt").html("thumbUrl:"+data.thumbUrl+"</br>"+"fileUrl:"+data.fileUrl);
	        	}else{
	        		alert(data.MSG);
	        	}
	        },
	        error: function (data) {
	            alert("error");
	        }
	    });
	  
	}
	function as(){
	  var data = { fileType:$("#fileType01").val(), userId:$("#userId01").val() } ;
	    $.ajaxFileUpload({
	        url: '<%=request.getContextPath()%>/file/uploads',
	        secureuri: true,
	        data: data,
	        fileElementId: ['fileToUpload01','fileToUpload02'],
	        dataType: "json",
	        success: function (data) {
	        	alert("成功");
	        	if(data.status==0){
	        		$("#h2tt").html("thumbUrl:"+data.thumbUrl+"</br>"+"fileUrl:"+data.fileUrl);
	        	}else{
	        		alert(data.MSG);
	        	}
	        },
	        error: function (data) {
	            alert("error");
	        }
	    });
	  
	}
	$(function(){
		
 
	param = parse_str(window.location.search);
		alert(param['teststr1']);
	});
	function parse_str(url) {
  		var qs = url.split('?').pop().split('&');
  		var qso = {} 
  		for(var i=0;i<qs.length;i++){
	    if(qs[i]=="") continue;
	    var tmpa = qs[i].split("=");
	    qso[tmpa[0]] = tmpa[1]?tmpa[1]:"";
	   
	  }
	  return qso;
	}
</script>
</head>
<body>
		<a href=""></a>
		<h2 id="h2tt"></h2>

		<form action="<%=request.getContextPath()%>/file/upload" method="post" ENCTYPE="multipart/form-data" >
			<p>
				<input id='fileToUpload' type="file" value="" name="file" />
			</p>
			<p>
				文 件类型:<input id='fileType01' type="text" name="fileType" value="0"/>
			</p>
			<p>
				Telephone:<input id="userId01" type="text"
					value="15000985612" name="userId" />
			</p>
			<p>
				<input  type="submit" value="Submit" />
			</p>
			<input onclick="abc()" type="button" value="ajax提交"/>
		</form>
		<h1>多文件上传</h1>
		<form action="<%=request.getContextPath()%>/file/uploads" method="post" ENCTYPE="multipart/form-data" >
			<p>
				<input id='fileToUpload01' type="file" value="" name="files" />
			</p>
			<p>
				<input id='fileToUpload02' type="file" value="" name="files" />
			</p>
			<p>
				文 件类型:<input id='fileType' type="text" name="fileType" value="0"/>
			</p>
			<p>
				Telephone:<input id="userId" type="text"
					value="15000985612" name="userId" />
			</p>
			<p>
				<input  type="submit" value="Submit" />
			</p>
			<input onclick="as()" type="button" value="ajax提交"/>
		</form>
		
</body>

</html>
